# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        潘炎珍  
# Name:         test02
# Description:
# Author:       98745
# Date:         2019/4/24
#-------------------------------------------------------------------------------
import requests
from lxml import etree
from bs4 import *

url='https://www.zhihu.com/signup?next=%2F'
headers={'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
z1=requests.get(url,headers=headers)
sel = BeautifulSoup(z1.text,'lxml')
# 这个xsrf怎么获取 我们上面有讲到
try:
    _xsrf = sel.find('input',{'name':'_xsrf'})['value']
    loginurl = 'https://www.zhihu.com/login/email'
except Exception as e:
    print(e)
# 这里的_xsrf就是我们刚刚上面得到的
formdata = {

    'email':'admin@wuaics.cn',

    'password':'你的密码',

    '_xsrf':_xsrf

}
z2 = requests.post(url=loginurl,data=formdata,headers=headers)
print(z2.status_code)
 #200
print(z2.content)
# '{"r":0,\n "msg": "\\u767b\\u5f55\\u6210\\u529f"\n}'
print(z2.json()['msg'])
# 登陆成功

